package jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.sql.SQLException;

public class Demo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()) {
            Statement statement = connection.createStatement();
            /*
            SELECT c.name,c.floor, t.name,t.salary,t.title
            FROM class c
            JOIN teacher t ON c.teacher_id = t.id
             */
            String sql=" SELECT c.name,c.floor, t.name,t.salary,t.title\n" +
                    "            FROM class c\n" +
                    "            JOIN teacher t ON c.teacher_id = t.id";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
                String cName=rs.getString("name");
                int cFloor=rs.getInt("floor");
                String tName=rs.getString("name");
                int tSalary=rs.getInt("salary");
                String tTitle=rs.getString("title");
                System.out.println("班级名："+cName+" 楼层："+cFloor+" 教师名："+tName+" 工资："+tSalary+" 职位："+tTitle);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
